package br.ufla.pgcc.oomeasures.measures;

import org.eclipse.jdt.core.dom.CompilationUnit;

import br.ufla.pgcc.oomeasures.astvisitors.ClassVisitor;

/**
 * Classe que implementa a medida NumberOfClasses, que indica o número de classes de um projeto.
 * O domínio de seus valores é [0,∞].
 * @author Mariana Azevedo
 *
 */
public class NumberOfClasses extends Measure{

	private double value;
	
	public NumberOfClasses(){
		super();
		value = 0d;
		addApplicableGranularity(Granularity.PROJECT);
	}
	
	@Override
	public String getName() {
		return "Number of Classes";
	}

	@Override
	public String getAcronym() {
		return "NC";
	}

	@Override
	public String getDescription() {
		return "Return the number of classes and inner classes of a class in a project";
	}

	@Override
	public double getMinValue() {
		return 0;
	}

	@Override
	public double getMaxValue() {
		return -1;
	}

	@Override
	public double getRefValue() {
		return -1;
	}

	@Override
	public double getCalculatedValue() {
		return value;
	}

	@Override
	public void setCalculatedValue(double value) {
		this.value = value;
	}

	@Override
	public <T> void measure(T unit) {
		
		// Now create the AST for the ICompilationUnits
		CompilationUnit parse = parse(unit);
		ClassVisitor visitor = new ClassVisitor();
		parse.accept(visitor);

		setCalculatedValue(getNumberOfClasses(visitor));
	}
	
	private int getNumberOfClasses(ClassVisitor visitor){
		 return visitor.getNumOfClasses();
	}

}
